# Copyright (c) 2024 IndustrialTBB Framework
# Licensed under MIT License

cmake_minimum_required(VERSION 3.16)

project(IndustrialTBB
    VERSION 1.0.0
    DESCRIPTION "Complete TBB-native Industrial Control Framework"
    LANGUAGES CXX
)

# 设置C++标准
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)

# 编译选项
if(MSVC)
    add_compile_options(/W4)
else()
    add_compile_options(-Wall -Wextra -Wpedantic)
endif()

# 查找依赖
find_package(TBB REQUIRED)

# 包含目录
include_directories(include)

# 添加子目录
add_subdirectory(src)
add_subdirectory(examples)

# 安装头文件
install(DIRECTORY include/itbb
    DESTINATION include
    FILES_MATCHING PATTERN "*.h"
)

# 生成配置文件
include(CMakePackageConfigHelpers)

configure_package_config_file(
    "${CMAKE_CURRENT_SOURCE_DIR}/cmake/itbb-config.cmake.in"
    "${CMAKE_CURRENT_BINARY_DIR}/itbb-config.cmake"
    INSTALL_DESTINATION lib/cmake/itbb
)

write_basic_package_version_file(
    "${CMAKE_CURRENT_BINARY_DIR}/itbb-config-version.cmake"
    VERSION ${PROJECT_VERSION}
    COMPATIBILITY SameMajorVersion
)

# 安装配置文件
install(FILES
    "${CMAKE_CURRENT_BINARY_DIR}/itbb-config.cmake"
    "${CMAKE_CURRENT_BINARY_DIR}/itbb-config-version.cmake"
    DESTINATION lib/cmake/itbb
)

# 导出目标
install(EXPORT itbb-targets
    FILE itbb-targets.cmake
    NAMESPACE itbb::
    DESTINATION lib/cmake/itbb
)
